﻿using Microsoft.EntityFrameworkCore;
using Simple.Admin.System.Enums;
using Simple.Admin.System.Identity;
using Volo.Abp.Identity;
using Volo.Abp.ObjectExtending;
using Volo.Abp.Threading;

namespace Simple.Admin.EntityFrameworkCore;

public static class AdminEfCoreEntityExtensionMappings
{
    private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();

    public static void Configure()
    {
        AdminGlobalFeatureConfigurator.Configure();
        AdminModuleExtensionConfigurator.Configure();

        OneTimeRunner.Run(() =>
        {
            ObjectExtensionManager.Instance
                .MapEfCoreProperty<IdentityUser, GenderEnum>(
                    IdentityUserExtensionPropertyConst.User.Gender,
                    (entityBuilder, propertyBuilder) =>
                    {
                        propertyBuilder.HasDefaultValue(GenderEnum.Other);
                    }
                )
                .MapEfCoreProperty<IdentityUser, string?>(
                    IdentityUserExtensionPropertyConst.User.AvatarUrl,
                    (entityBuilder, propertyBuilder) =>
                    {
                        propertyBuilder.HasDefaultValue(string.Empty);
                    }
                )
                .MapEfCoreProperty<IdentityUser, string?>(
                    IdentityUserExtensionPropertyConst.User.Province,
                    (entityBuilder, propertyBuilder) =>
                    {
                        propertyBuilder.HasDefaultValue(string.Empty);
                    }
                )
                .MapEfCoreProperty<IdentityUser, string?>(
                    IdentityUserExtensionPropertyConst.User.City,
                    (entityBuilder, propertyBuilder) =>
                    {
                        propertyBuilder.HasDefaultValue(string.Empty);
                    }
                )
                .MapEfCoreProperty<IdentityUser, string?>(
                    IdentityUserExtensionPropertyConst.User.District,
                    (entityBuilder, propertyBuilder) =>
                    {
                        propertyBuilder.HasDefaultValue(string.Empty);
                    }
                )
                .MapEfCoreProperty<IdentityUser, string?>(
                    IdentityUserExtensionPropertyConst.User.Introduction,
                    (entityBuilder, propertyBuilder) =>
                    {
                        propertyBuilder.HasDefaultValue(string.Empty);
                    }
                )
                .MapEfCoreProperty<IdentityUser, string?>(
                    IdentityUserExtensionPropertyConst.User.Address,
                    (entityBuilder, propertyBuilder) =>
                    {
                        propertyBuilder.HasDefaultValue(string.Empty);
                    }
                );
        });
    }
}
